package com.xiaoming.backend.controller;

import com.xiaoming.backend.dao.IWasteCategoryDao;
import com.xiaoming.backend.entity.orm.DisposalMethod;
import com.xiaoming.backend.entity.orm.WasteCategory;
import com.xiaoming.backend.result.exception.AppErrorException;
import com.xiaoming.backend.result.exception.error.AppError;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/enum")
@RequiredArgsConstructor
@PreAuthorize("@securityService.checkInstitution(#institutionId)")
@Tag(name = "IEnumContrller", description = "获得一些枚举值")
public class IEnumContrller {

    private final IWasteCategoryDao wasteCategoryDao;

    @GetMapping("/categori")
    @Operation(summary = "wasteCategori", description = "获取废物类型")
    public ResponseEntity<?> wasteCategori() {
        try {
            List<WasteCategory> wasteCategories = wasteCategoryDao.getWasteCategoryPO();
            return ResponseEntity.ok(wasteCategories);
        }catch (AppErrorException e){
            return ResponseEntity.status(HttpStatus.FORBIDDEN).body(e.getErrorMsg());
        }
    }

    @GetMapping("/disposal/method")
    @Operation(summary = "disposalMethod", description = "获取废物处理方式")
    public ResponseEntity<?> disposalMethod() {
        try {
            List<DisposalMethod> disposalMethods = wasteCategoryDao.getDisposalMethodPO();
            return ResponseEntity.ok(disposalMethods);
        }catch (AppErrorException e){
            return ResponseEntity.status(HttpStatus.FORBIDDEN).body(e.getErrorMsg());
        }
    }

}
